<template>
  <ant-modal modalWidth="1360" modalHeight="600" :visible="open" :modal-title="formTitle" :adjust-size="true" :maskClosable="false"
    @cancel="cancel">
    <a-form-model ref="form" :model="form" :rules="rules" slot="content">
      <biz-product v-if="showProductModal" ref="bizProduct" @ok="selectProduct" @close="showProductModal = false" />
      <a-row :gutter="32">
        <a-col :span="12">
          <a-form-model-item label="采购单编号">
            {{ form.purchaseCode }}
          </a-form-model-item>
        </a-col>
        <a-col :span="12">
          <a-form-model-item label="供应商">
            {{ form.supplierName }}
          </a-form-model-item>
        </a-col>
        <a-col :span="12">
          <a-form-model-item label="采购日期">
            {{ form.purchaseDate }}
          </a-form-model-item>
        </a-col>
        <a-col :span="12">
          <a-form-model-item label="采购金额">
            {{ form.purchaseAmount }}
          </a-form-model-item>
        </a-col>
        <a-col :span="12">
          <a-form-model-item label="付款金额">
            {{ form.payAmount }}
          </a-form-model-item>
        </a-col>
        <a-col :span="12">
          <a-form-model-item label="应付余额">
            {{ form.purchaseAmount - form.payAmount }}
          </a-form-model-item>
        </a-col>
        <a-col :span="24">
          <a-card :bordered="false">
            <advance-table :loading="loading" rowKey="id" size="middle" :columns="columns1" :data-source="form.payList"
              :pagination="false" :bordered="true">
              <div class="table-operations" slot="button" style='margin-bottom:0px;'>
                <div class="table_title">付款明细</div>
                <a-button type="primary" @click="handleAddPay" >
                  <a-icon type="plus" />新增
                </a-button>
              </div>
              <span slot="unitSlot" slot-scope="{record}">
                <a-select placeholder="请选择单位" v-model="record.unit" :getPopupContainer="triggerNode => {
                    return triggerNode.parentNode || document.body
                  }
                  " style="width: 100%" allow-clear @change='changeUnit(record)'>
                  <a-select-option v-for="(d, index) in record.unitList" :key="index" :value="d.key">{{ d.name
                  }}</a-select-option>
                </a-select>
              </span>
              <span slot="payAccountSlot" slot-scope="{record}">
                <a-select placeholder="请选择账户" v-model="record.payAccount" style="display:block" v-if="record.flag == false">
                  <a-select-option v-for="(d, index) in payOptions" :key="index" :value="d.dictLabel">{{ d.dictLabel }}</a-select-option>
                </a-select>
                <span v-else>
                  {{ record.payAccount }}
                </span>
              </span>
              <span slot="payAmountSlot" slot-scope="{record}">
                <a-input type='text' placeholder="请输入金额" v-model="record.payAmount" v-if="record.flag == false"/>
                <span v-else>
                  {{ record.payAmount }}
                </span>
              </span>
              <span slot="payDateSlot" slot-scope="{record}">
                <a-date-picker format="YYYY-MM-DD" v-model="record.payDate" @change="changeDate(record)" :show-today="true" v-if="record.flag == false"/>
                <span v-else>
                  {{ record.payDate }}
                </span>
              </span>
              <span slot="remarkSlot" slot-scope="{record}">
                <a-input type='text' placeholder="请输入备注" v-model="record.remark" v-if="record.flag == false"/>
                <span v-else>
                  {{ record.remark }}
                </span>
              </span>
              <span slot="operation" slot-scope="{record}">
                <a @click="savePay(record)" v-if="!record.id || record.flag == false" v-hasPermi="['biz:bizOrder:edit']">
                  保存
                </a>
                <a @click="handlePayDelete(record)" v-hasPermi="['biz:bizOrder:remove']">
                  删除
                </a>
              </span>
            </advance-table>
          </a-card>
        </a-col>
      </a-row>

    </a-form-model>
    <template slot="footer">
      <a-button  @click="cancel">
        取消
      </a-button>
    </template>
  </ant-modal>
</template>
<script>
import BizPurchaseForm from './BizPurchaseForm'
export default {
  ...BizPurchaseForm
}
</script>
<style lang="less" scoped>
.table-operations,
body tr.ant-table-expanded-row:hover .table-operations {
  padding-bottom: 8px;
  text-align: right;
}

.table-operations {
  margin-bottom: 16px;
}

.table-operations>button,
.table-operations .ant-input-affix-wrapper {
  margin-right: 8px;
}

.table_title {
  float: left;
  padding-left: 8px;
  font-weight: 600;
  color: #222222;
  line-height: 30px;
}
</style>
